package com.next.muscu.visual;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.GridLayout;

import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;


import com.next.muscu.data.ExoType;
import com.next.muscu.data.GenericListModel;
import com.next.muscu.data.ObservableList;
import com.next.muscu.data.User;


public class VisualUserRecordPanel extends JPanel {

	JPanel choixUtilisateurPanel = new JPanel();
	JPanel detailUtilisateurPanel = new JPanel();
	JComboBox utlisateurComboBox = new JComboBox();
	ObservableList<ExoType>  userComboData  = new ObservableList<ExoType>("from User");
	
	public VisualUserRecordPanel(Dimension dimension)
	{
		this.setPreferredSize(dimension);
		BuildGui();
	}
	
	private void BuildGui()
	{
		this.setLayout(new BoxLayout(this,BoxLayout.Y_AXIS));
		BuildChoixUtilisateurPanel();
		BuildDetailUtilisateurPanel();
		this.add(choixUtilisateurPanel);
		this.add(Box.createVerticalGlue());
		this.add(detailUtilisateurPanel);
	}
	private void BuildDetailUtilisateurPanel()
	{
		JTabbedPane tabbedPane = new JTabbedPane();
		
		tabbedPane.addTab("Donn�es g�n�rales", null,BuidGeneralPanel() ,
        "Does nothing");
		JComponent panel2 = makeTextPanel("Panel #2");
		tabbedPane.addTab("Tab 2", null, panel2,
        "Does nothing 2");
		detailUtilisateurPanel.setLayout(new BoxLayout(detailUtilisateurPanel,BoxLayout.X_AXIS));
		detailUtilisateurPanel.add(tabbedPane);
	}
    
	protected JComponent makeTextPanel(String text) {
        JPanel panel = new JPanel(false);
        JLabel filler = new JLabel(text);
        filler.setHorizontalAlignment(JLabel.CENTER);
        panel.setLayout(new GridLayout(1, 1));
        panel.add(filler);
        return panel;
    }
	private JPanel BuidGeneralPanel()
	{
		JPanel panel1 = new JPanel();
		panel1.setLayout(new BoxLayout(panel1, BoxLayout.Y_AXIS));
		panel1.add(new VisualUserSimplePanel());
		return panel1;
		
	}
	private void BuildChoixUtilisateurPanel()
	{		
		utlisateurComboBox.setRenderer(new UserJlistCellRender());
		GenericListModel<User> comboModel = new GenericListModel(userComboData); 
		utlisateurComboBox.setPreferredSize(new Dimension(200,20));
		utlisateurComboBox.setMaximumSize(new Dimension(800,20));
		utlisateurComboBox.setModel(comboModel);
		utlisateurComboBox.setAlignmentY(TOP_ALIGNMENT);
		JButton btSetDefaultUser = new JButton("Utilisateur par d�faut");
		btSetDefaultUser.setAlignmentY(TOP_ALIGNMENT);
		choixUtilisateurPanel.setLayout(new BoxLayout(choixUtilisateurPanel,BoxLayout.X_AXIS));
		choixUtilisateurPanel.setAlignmentY(TOP_ALIGNMENT);
		choixUtilisateurPanel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createLineBorder(Color.black), "choix de l'utilisateur"));
		choixUtilisateurPanel.add(utlisateurComboBox);
		choixUtilisateurPanel.add(Box.createHorizontalStrut(20));
		choixUtilisateurPanel.add(btSetDefaultUser);
		choixUtilisateurPanel.setPreferredSize(new Dimension(this.getPreferredSize().width,50));
		choixUtilisateurPanel.setMaximumSize(new Dimension(this.getPreferredSize().width,50));
	}
}
